package cn.openea.perpartner.meily.web.mapper;

import cn.openea.perpartner.meily.web.entity.LogisticsInfo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * @author ysk
 * @email zane_ysk@qq.com
 * @date 2023-05-10 13:57:42
 */
@Mapper
public interface LogisticsInfoMapper extends BaseMapper<LogisticsInfo> {

    /**
     * 物流状态统计
     * @param buildQueryWrapper
     * @return map
     */
    @Select("SELECT SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END)          AS SIGN,\n" +
            "       SUM(CASE WHEN status <> 3 THEN 1 ELSE 0 END)          AS IN_TRANSIT,\n" +
            "       SUM(CASE WHEN business_status = 1 THEN 1 ELSE 0 END) AS BUSINESS_COMPLETED\n" +
            "FROM meily_logistics_info ${ew.customSqlSegment}")
    Map<String, Integer> logisticsStatusStatistics(@Param("ew") LambdaQueryWrapper<LogisticsInfo> buildQueryWrapper);
}
